package com.ellricky.baselib.ui.reserve;


import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;

import com.andr.common.http.callback.BaseCallback;
import com.andr.common.ui.adapter.BaseRecyclerAdapter;
import com.andr.common.ui.mvp.BasePresenter;
import com.ellricky.baselib.R;
import com.ellricky.baselib.adapter.reserve.CtReserveAdapter;
import com.ellricky.baselib.entity.reserve.CtReserveEntity;
import com.ellricky.baselib.http.callback.EListCallback;
import com.ellricky.baselib.ui.base.BaseRefreshFragment;
import com.ellricky.baselib.util.EAppUtil;

import java.util.List;

import static com.ellricky.baselib.http.Api.API_CT_RESERVE_LIST;

public class ReserveListFragment extends BaseRefreshFragment<Void, BasePresenter<Void>, CtReserveEntity> {

    public static ReserveListFragment newInstance() {
        ReserveListFragment fragment = new ReserveListFragment();
        Bundle bundle = new Bundle();
        fragment.setArguments(bundle);
        return fragment;
    }


    @Override
    public void initUIView(View view) {
        super.initUIView(view);
        mTvTitle.setText(R.string.base_order_manage);
    }

    @Override
    protected BaseCallback getResponseCallback() {
        return  new EListCallback<CtReserveEntity> (mContext) {
            @Override
            protected void onSuccess(List<CtReserveEntity> data, String msg) {
                dataSource = data;
                rvView.onLoadFinish(dataSource, refresh);
            }

            @Override
            protected void onErrorCode(String code, String msg) {
                super.onErrorCode(code, msg);
                rvView.onRefreshFailed(refresh);
            }

            @Override
            protected void onHttpError(String code, String msg) {
                super.onHttpError(code, msg);
                rvView.onRefreshFailed(refresh);
            }
        };
    }


    @Override
    protected BaseRecyclerAdapter<CtReserveEntity> getRvAdapter() {
        return new CtReserveAdapter(mContext);
    }

    @Override
    protected String getUrlPath() {
        return API_CT_RESERVE_LIST;
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
        super.onItemClick(adapterView, view, position, l);
        CtReserveEntity entity = adapter.get(position);
        EAppUtil.jumpPageWithId(this, CtReserveDetailActivity.class, entity.getId());
    }

}